package com.newsnetwork.article.controller;

import com.newsnetwork.api.config.RabbitMQConfig;
import com.newsnetwork.grace.result.CommonJSONResult;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author DingNing
 * @date 2022/11/9 22:10
 * @Description: 测试
 */
@RestController
@RequestMapping("producer")
public class HelloController {

    @Autowired
    private RabbitTemplate rabbitTemplate;

    @GetMapping("/hello")
    public Object hello() {

        /**
         * RabbitMQ 的路由规则 routing key
         *  display.*.* -> * 代表一个占位符
         *      例：
         *          display.do.download  匹配
         *          display.do.upload.done   不匹配
         *
         * display.# -> # 代表任意多个占位符
         *      例:
         *          display.do.download  匹配
         *          display.do.upload.done.over   匹配
         *
         *
         */

        rabbitTemplate.convertAndSend(
                RabbitMQConfig.EXCHANGE_ARTICLE,
                "article.hello",
                "这是从生产 者发送的消息~");

//        rabbitTemplate.convertAndSend(
//                RabbitMQConfig.EXCHANGE_ARTICLE,
//                "article.publish.download.do",
//                "1001");
//
//
//
//        rabbitTemplate.convertAndSend(
//                RabbitMQConfig.EXCHANGE_ARTICLE,
//                "article.success.do",
//                "1002");
//
//        rabbitTemplate.convertAndSend(
//                RabbitMQConfig.EXCHANGE_ARTICLE,
//                "article.play",
//                "1003");

        return CommonJSONResult.ok();
    }

}
